home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part1 / 3248 < prev    next >
Encoding:
Internet Message Format  |  1996-08-06  |  1.8 KB

  1. Path: atglab.bls.com!Alun.Champion
  2. From: Alun.Champion@bridge.bst.bls.com (Alun Champion)
  3. Newsgroups: comp.lang.c++
  4. Subject: Re: [] overload..(newbie in distress)
  5. Date: 22 Jan 1996 23:50:45 GMT
  6. Organization: Computer People Inc.
  7. Message-ID: <ALUN.CHAMPION.96Jan22185045@g7240065.bridge.bst.bls.com>
  8. References: <DLGppJ.31C@undergrad.math.uwaterloo.ca>
  9.     <Robert.Lendvai-2101960118330001@129.170.80.94>
  10.     <4dtuam$hf4@news.xmission.com>
  11.     <ALUN.CHAMPION.96Jan22143422@g7240065.bridge.bst.bls.com>
  12. NNTP-Posting-Host: bstfirewall.bst.bls.com
  13. In-reply-to: Alun.Champion@bridge.bst.bls.com's message of 22 Jan 1996
  14.     19:34:22 GMT
  15.  
  16. In article <ALUN.CHAMPION.96Jan22143422@g7240065.bridge.bst.bls.com> Alun.Champion@bridge.bst.bls.com (Alun Champion) writes:
  17.  
  18. : In article <4dtuam$hf4@news.xmission.com> tknarr@xmission.com  ( Todd Knarr ) writes:
  19.  
  20. : : tthiraku@landen.math.uwaterloo.ca (Thanou Thirakul) wrote:
  21. : :>     A[5] = val;  // store val into the fifth node of a linklist. 
  22. : :>     val = A[5] ; // returns the value of the fifth node of a linklist.  
  23.  
  24. :    T& operator [] (int index);
  25. :    T operator [] (int index) const;
  26.  
  27. : : It involves the return value of the operator[]() function. If it
  28. : : returns a reference, you can use it on the left side of the assignment.
  29. : : If it returns a non-reference, you can't.
  30.  
  31. : A reference can also be used on the right of an assignment also.
  32.  
  33. : Does anyone have any good reasons or references as why you should define the
  34. : second of the two operator []'s if you provide the first ?
  35.  
  36. For const list of course, dopey sod. ;')
  37. Oops, guess I didn't long enough on this one, but still doesn't answer the
  38. question below.
  39.  
  40. : And if it is necessary what is the argument against
  41.  
  42. :    const T& operator [] (int index) const;
  43.  
  44. : instead ?
  45.  
  46. Regards
  47.  
  48.    -A.
  49. -- 
  50. | A.Champion                |
  51.